﻿using System;
using System.Text;
using System.Collections.Generic;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Chaliy.DbPro.Generators.TextAuthoring;
using Chaliy.DbPro.Generators.TextAuthoring.Configuration;
using System.Collections.ObjectModel;

namespace Chaliy.DbPro.Generators.Tests.TextAuthoring
{	
	[TestClass]
	public class RandomWordAuthorTests
	{		
		[TestMethod]
		[DeploymentItem(DeploymentConstants.GeneratorsDll)]
		public void TestNormalFlowGeneration()
		{

			List<string> terms = new List<string>
			{
				"Bob",
				"Rob",
				"Dob"
			};

			IWordAuthor author = new RandomWordAuthor(
                TermAccessorUtilities.Create(terms)
				);

			string result = author.Generate();

			CollectionAssert.Contains(terms, result);
		}

		[TestMethod]
		[DeploymentItem(DeploymentConstants.GeneratorsDll)]		
		public void TestGenerationWithSingleTerm()
		{
			const string term = "Bob";
			List<string> terms = new List<string>{ term };				

			IWordAuthor author = new RandomWordAuthor(
				TermAccessorUtilities.Create(terms)
				);
			
			string result = author.Generate();

			Assert.AreEqual(term, result);
		}

        [TestMethod]
        [DeploymentItem(DeploymentConstants.GeneratorsDll)]
		[ExpectedException(typeof(TextAuthorException))]
        public void TestGenerationWithEmptyTermList()
        {

            List<string> terms = new List<string>();            

            IWordAuthor author = new RandomWordAuthor(
                TermAccessorUtilities.Create(terms)
                );

			// Waiting for exception because 
			// author cannot work without words...
            author.Generate();            
        }

		[TestMethod]
		[DeploymentItem(DeploymentConstants.GeneratorsDll)]
		[ExpectedException(typeof(ArgumentNullException))]
		public void TestConstructorEmptyArgument()
		{

			// Expecitn exception here because 
			// author cannot work without term provider
			new RandomWordAuthor(null);			
		}
	}

}
